import type { Patient, PatientList, UserInfo, mobileCode } from '@/types/user'
import request from '@/utils/request'

// 每个接口对应封装一个api函数
type ILoginType = {
  token: string
  refreshToken: string
  avatar: string
  mobile: string
  account: string
  id: string
}
// 登录
export const loginByPassword = (data: any) => {
  return request<ILoginType>('login/password', 'post', data)
}

// 验证码登录
export const loginByCode = (data: { mobile: string; code: string }) => {
  return request<ILoginType>('login', 'post', data)
}

// 获取用户信息
export const getUserInfo = () => {
  return request<UserInfo>('patient/myUser')
}

// 获取验证码
export const getMobileCode = (data: { mobile: string; type: mobileCode }) => {
  return request<{ code: string }>('/code', 'get', data)
}

// 获取家庭档案
export const getPatientList = () => {
  return request<PatientList>('/patient/mylist')
}

// 添加家庭档案接口
export const addPatient = (data: Patient) => {
  return request<{ id: string }>('/patient/add', 'POST', data)
}

// 编辑家庭档案接口
export const updatePatient = (data: Patient) => {
  return request<{ id: string }>('/patient/update', 'put', data)
}

// 删除家庭档案接口
export const delPatientInfo = (id: string) => {
  return request<{ id: string }>(`patient/del/${id}`, 'DELETE')
}

// 获取患者信息
export const getPatientDetail = (id: string) => {
  return request<Patient>(`/patient/info/${id}`)
}
